
* * * * * * * * FIGURE 1 * * * * * * * * 
use "$temp\reg_coeffs_pos_all years_linear.dta", clear
append using "$temp\reg_coeffs_ppo_all years_linear.dta"

preserve
	keep if var == "wtp_pp"
	gen sig = pval<0.05
	sort coef
	gen area_num = _n
	
	*Figure 1
	twoway rcap ci_lower ci_upper area_num, lcolor(gs5) || (scatter coef area_num if sig == 0, mcolor(gs10)) (scatter coef area_num if sig == 1, mcolor(black)), xtitle("Analysis Areas") ///
	ytitle("WTPPP Coefficient Estimates") yline(0, lstyle(foreground)) legend(label(1 95% CI) label(2 Not Significant) label(3 Significant at p<0.05) rows(1))
	graph save "$output\WTP Coeffs_linear.gph", replace
	
	sum coef, det

	tab sig prod
	tab prod if coef < 0
	tab sig if coef < 0
restore

*Figure A1
keep if var == "_cons"
gen sig = pval<0.05
sort coef
gen area_num = _n
twoway rcap ci_lower ci_upper area_num, lcolor(gs5) || (scatter coef area_num if sig == 0, mcolor(gs10)) (scatter coef area_num if sig == 1, mcolor(black)), xtitle("Analysis Areas") ///
ytitle("Constant Term Estiamtes") yline(0, lstyle(foreground)) legend(label(1 95% CI) label(2 Not Significant) label(3 Significant at p<0.05) rows(1))
graph save "$output\Constant Coeffs_linear.gph", replace


*Set price-wtp regression mean coefficients 
local bdtot = 1.09
local pct_mcr = -1134.95
local pct_mcd = 631.98
local teaching = -115.32
local forprofit = 1242.33
local ftres = .77
local noncbsa = 669.48
local y12 = 525.13
local y13 = 877.68
local y14 = 1627.95

* * * Set Price-WTP regression control means 
local mean_bdtot = 299.320
local mean_pct_mcr = .462
local mean_pct_mcd = .190
local mean_teaching = .418
local mean_forprofit = .167
local mean_ftres = 61.632
local mean_noncbsa = .019
local mean_y12 = .256
local mean_y13 = .248
local mean_y14 =.236

*Set mean WTP/Constant - IHHI regression controls: 
local mean_ppo = .198
local mean_lt200pl = .346
local mean_unins = .154
local mean_util = .670

* * * * * without controls:

*Set alphs coefficients
local a_ihhi = 17164
local a_ppo = 1954
local a_pct_lt200pl = 0
local a_pct_unins = 0
local a_hosp_util = 0
local a_constant = 855

*Set delta coefficients
local d_ihhi = -12967
local d_ppo = -2155
local d_pct_lt200pl = 0
local d_pct_unins = 0
local d_hosp_util = 0
local d_constant = 8066


* * * * * * * * FIGURE 2 * * * * * * * * 
*By IHHI percentiles (25, 50, 75) 
foreach ihhi in 3654 4427 5386 {

	clear
	save "$temp\data_for_fig2_`ihhi'.dta", replace emptyok

	local i = 1
	local alpha_hat = ((`a_constant') + (`a_ihhi'*(`ihhi'/10000)) + (`a_ppo'*`mean_ppo') + (`a_pct_lt200pl'*`mean_lt200pl') + (`a_pct_unins'*`mean_unins') + (`a_hosp_util'*`mean_util'))
	local delta_hat = ((`d_constant') + (`d_ihhi'*(`ihhi'/10000)) + (`d_ppo'*`mean_ppo') + (`d_pct_lt200pl'*`mean_lt200pl') + (`d_pct_unins'*`mean_unins') + (`d_hosp_util'*`mean_util'))
	
	*WTP 1st to 99th percentile 
	forv wtp = 1.00(.0109)2.09 {
		set obs 1
		gen alpha_`ihhi' = 1*`alpha_hat'
		gen delta_`ihhi' = 1*`delta_hat'
		gen price_ihhi_`ihhi' = `alpha_hat' + (`delta_hat'*`wtp') + (`bdtot'*`mean_bdtot') + (`pct_mcr'*`mean_pct_mcr') + (`pct_mcd'*`mean_pct_mcd') + (`teaching'*`mean_teaching') ///
		+ (`forprofit'*`mean_forprofit') + (`ftres'*`mean_ftres') + (`noncbsa'*`mean_noncbsa') + (`y12'*`mean_y12') + (`y13'*`mean_y13') + (`y14'*`mean_y14')
		gen obs = `i'
		gen wtp = `wtp'
		local i = `i' + 1
		append using "$temp\data_for_fig2_`ihhi'.dta"
		save "$temp\data_for_fig2_`ihhi'.dta", replace
		clear
	}
	
}

clear
set obs 101
gen obs = _n
save "$temp\data_for_fig2", replace

foreach ihhi in 3654 4427 5386 {
use "$temp\data_for_fig2", clear
merge 1:1 obs using "$temp\data_for_fig2_`ihhi'.dta"
assert _m == 3
drop _m
save "$temp\data_for_fig2", replace
}

use "$temp\data_for_fig2", clear 
sort obs
order obs wtp  

line price_ihhi_3654 wtp, lcolor(gs9) lp(shortdash) || line price_ihhi_4427 wtp, lcolor(black) || line price_ihhi_5386 wtp, lcolor(gs9) lp(longdash) ytitle("Average hospital price ($)") ysc(r(10000 15000)) ///
ylabel(10000(1000)15000,format(%9.0fc) labsize(vsmall) angle(45)) yline(12240, lcolor(gs12) lp(dot)) xlabel(1.0(.1)2.1) xtitle("WTPPP") ///
legend(label(1 "IHHI 25th percentile") label(2 "IHHI 50th percentile") label(3 "IHHI 75th percentile") size(vsmall) rows(1))
graph export "$output\Figure 2.pdf", replace



* * * * * * * * FIGURE 3 * * * * * * * * 
*By IHHI percentiles (25, 50, 75) 
foreach ihhi in 3654 4427 5386 {

	clear
	save "$temp\data_for_fig3_`ihhi'.dta", replace emptyok

	local i = 1
	local alpha_hat = ((`a_constant') + (`a_ihhi'*(`ihhi'/10000)) + (`a_ppo'*`mean_ppo') + (`a_pct_lt200pl'*`mean_lt200pl') + (`a_pct_unins'*`mean_unins') + (`a_hosp_util'*`mean_util'))
	local delta_hat = ((`d_constant') + (`d_ihhi'*(`ihhi'/10000)) + (`d_ppo'*`mean_ppo') + (`d_pct_lt200pl'*`mean_lt200pl') + (`d_pct_unins'*`mean_unins') + (`d_hosp_util'*`mean_util'))
	
	*Mean WTP: 1.26 (SD .23)
	*Median WTP: 1.22 (IQR .28)
	*Ave percent change from Garmon: .144 (SD .143)
	*Med percent change from Garmon: .073 (IQR .194) 

	foreach wtp in 1.26 1.35 1.44 {
		set obs 1
		gen alpha_`ihhi' = 1*`alpha_hat'
		gen delta_`ihhi' = 1*`delta_hat'
		gen price_ihhi_`ihhi' = `alpha_hat' + (`delta_hat'*`wtp') + (`bdtot'*`mean_bdtot') + (`pct_mcr'*`mean_pct_mcr') + (`pct_mcd'*`mean_pct_mcd') + (`teaching'*`mean_teaching') ///
		+ (`forprofit'*`mean_forprofit') + (`ftres'*`mean_ftres') + (`noncbsa'*`mean_noncbsa') + (`y12'*`mean_y12') + (`y13'*`mean_y13') + (`y14'*`mean_y14')
		gen obs = `i'
		gen wtp = `wtp'
		local i = `i' + 1
		append using "$temp\data_for_fig3_`ihhi'.dta"
		save "$temp\data_for_fig3_`ihhi'.dta", replace
		clear
	}
	
}

clear
set obs 3
gen obs = _n
save "$temp\data_for_fig3", replace

*By IHHI percentiles (25, 50, 75) 
foreach ihhi in 3654 4427 5386 {
	use "$temp\data_for_fig4", clear
	merge 1:1 obs using "$temp\data_for_fig3_`ihhi'"
	assert _m == 3
	drop _m
	save "$temp\data_for_fig3", replace
}

use "$temp\data_for_fig3", clear 
sort obs
order obs wtp  
keep if wtp == 1.26 | wtp == 1.44
drop alpha* delta* obs
replace wtp = wtp*100
reshape long price_ihhi_, i(wtp) j(ihhi)
reshape wide price_ihhi_, i(ihhi) j(wtp)
gen pct_change = 100*((price_ihhi_144-price_ihhi_126)/price_ihhi_126)
gen hhi_pct = ""
replace hhi_pct = "25th" if ihhi == 3654
replace hhi_pct = "50th" if ihhi == 4427
replace hhi_pct = "75th" if ihhi == 5386
gen pct_increase = pct_change
replace pct_increase = . if pct_change<0
gen pct_decrease = pct_change
replace pct_decrease = . if pct_change>0

graph bar (asis) pct_increase pct_decrease, over(hhi_pct) nofill ///
ytitle("Percent change in average price (%)") ylabel(0(1)5, format(%9.1f)) b2title("IHHI percentile") legend(off) bar(1, color(black))
graph export "$output\Figure 3.pdf", replace


exit
